import amesu from "../../model/bot/amesu";
import { Bot_msg } from "../../model/bot/bot_msg";
import browser, { tempDir } from "../../model/browser/browser";
import server from "../../model/client/server";
import { mathType, packge } from "../../model/msgHandle/packge";
import { rank_type, rank_typeName } from "../../shared/interface";
import { template } from "../../shared/master/MsgAction";
import { style_default } from "../../style/default";

class index extends packge {

    constructor() {
        super()
    }
    init(): void {
        this.addMath(mathType.math_start, '排行榜', ((msg: Bot_msg) => { this.list(msg) }), this)
        this.addMath(mathType.math_all, '等级排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/leve', type: rank_type.等级 }, msg) }), this, false)
        this.addMath(mathType.math_all, '战力排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/score', type: rank_type.战力 }, msg) }), this, false)
        this.addMath(mathType.math_all, '称号排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/title', type: rank_type.称号资质 }, msg) }), this, false)
        this.addMath(mathType.math_all, '血统排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/job_leve', type: rank_type.血统等级 }, msg) }), this, false)
        this.addMath(mathType.math_all, '天赋等级排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/tianfu_leve', type: rank_type.天赋等级 }, msg) }), this, false)
        this.addMath(mathType.math_all, '血统资质排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/job_score', type: rank_type.血统资质 }, msg) }), this, false)
        this.addMath(mathType.math_all, '天赋资质排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/tianfu_score', type: rank_type.天赋资质 }, msg) }), this, false)
        this.addMath(mathType.math_all, '魔攻排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/m_attack', type: rank_type.魔攻 }, msg) }), this, false)
        this.addMath(mathType.math_all, '魔防排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/m_defense', type: rank_type.魔防 }, msg) }), this, false)
        this.addMath(mathType.math_all, '物攻排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/p_attack', type: rank_type.物防 }, msg) }), this, false)
        this.addMath(mathType.math_all, '物防排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/p_defense', type: rank_type.物攻 }, msg) }), this, false)
        this.addMath(mathType.math_all, '生命排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/hp', type: rank_type.生命 }, msg) }), this, false)
        this.addMath(mathType.math_all, '富豪金币榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/gold', type: rank_type.金币 }, msg) }), this, false)
        this.addMath(mathType.math_all, '探险大师榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/move_cont', type: rank_type.步数 }, msg) }), this, false)
        this.addMath(mathType.math_all, '小队排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/team_contribute', type: rank_type.小队贡献 }, msg) }), this, false)
        this.addMath(mathType.math_all, '摸鱼排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/onhookTime', type: rank_type.挂机时长 }, msg) }), this, false)
        this.addMath(mathType.math_all, '肝帝刷怪榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/kill_enemy_cont', type: rank_type.击杀怪物数量 }, msg) }), this, false)
        this.addMath(mathType.math_all, '宝箱达人榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/openGiftBoxCont', type: rank_type.宝箱成功打开次数 }, msg) }), this, false)
        this.addMath(mathType.math_all, '宝可梦大师榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/pet_catch_SuccressCont', type: rank_type.捕捉宠物成功次数 }, msg) }), this, false)
        this.addMath(mathType.math_all, '基因锁排行榜', ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/dna_leve', type: rank_type.基因锁等级 }, msg) }), this, false)
        this.addMath(mathType.math_all, rank_typeName.委托完成次数排行榜, ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/entrustTask_cont', type: rank_type.委托完成次数排行榜 }, msg) }), this, false)
        this.addMath(mathType.math_all, rank_typeName.boss击杀次数, ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/boss_kill_cont', type: rank_type.boss击杀次数 }, msg) }), this, false)
        this.addMath(mathType.math_all, rank_typeName.签到次数, ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/sign_cont', type: rank_type.签到次数 }, msg) }), this, false)
        this.addMath(mathType.math_all, "名人堂", ((msg: Bot_msg) => { this.hof(msg) }), this, false)
        this.addMath(mathType.math_all, rank_typeName.新手任务完成耗时, ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/newbieuseTime', type: rank_type.新手任务完成耗时 }, msg) }), this, false)
        this.addMath(mathType.math_all, rank_typeName.每周任务完成次数, ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/task_everyday_cont', type: rank_type.每周任务完成次数 }, msg) }), this, false)
        this.addMath(mathType.math_all, rank_typeName.每日任务完成次数, ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/task_everyday_cont', type: rank_type.每日任务完成次数 }, msg) }), this, false)
        this.addMath(mathType.math_all, rank_typeName.钓鱼总斤数, ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/fishing_cont', type: rank_type.钓鱼总斤数 }, msg) }), this, false)
        this.addMath(mathType.math_all, rank_typeName.砍树次数, ((msg: Bot_msg) => { server.api('rank/Rank_look', { template: 'rank/chopping', type: rank_type.砍树次数 }, msg) }), this, false)

        
    }
    async hof(msg: Bot_msg) {
        let req = await server.api('openApi/NeverRank', {}, msg);
        if (!req) {
            return;
        }
        let name_data = await fetch(`https://api.oioweb.cn/api/qq/info?qq=${req.qq}`, {
            method: "GET",
            headers: {}
        })
        let info = await name_data.json();
        let _name = info.result.nickname;
        let icon_data = await fetch(`https://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins=${req.qq}`, {
            method: "GET",
            headers: {}
        })
        let icon_info = await icon_data.text();
        let jsonString = icon_info;
        let startIndex = jsonString.indexOf('(');
        let jsonContent = jsonString.substring(startIndex + 1, jsonString.length - 1);
        let jsonObject = JSON.parse(jsonContent);
        let arrayContent = jsonObject[req.qq];
        let icon = arrayContent[0];
        let name = arrayContent[6].length;
        browser.render(tempDir.名人堂, {
            icon:icon,
            name:_name.length == 0?req.qq:_name,
            res: req.res,
            game_state:req.online,
        }).then((png) => {
            amesu.sendLocaImage(msg.getFormId(), png);
        });
    }
    list(msg: Bot_msg) {
        let d = new style_default();
        d.addLine(`名人堂`)
        d.addLine(`战力排行榜`)
        d.addLine(`等级排行榜`)
        d.addLine(`称号排行榜`)
        d.addLine(`血统等级排行榜`)
        d.addLine(`血统资质排行榜`)
        d.addLine(`天赋等级排行榜`)
        d.addLine(`天赋资质排行榜`)
        d.addLine(`物攻排行榜`)
        d.addLine(`魔攻排行榜`)
        d.addLine(`物防排行榜`)
        d.addLine(`魔防排行榜`)
        d.addLine(`生命排行榜`)
        d.addLine(rank_typeName.委托完成次数排行榜)
        d.addLine(rank_typeName.boss击杀次数)
        d.addLine(`魔法排行榜`)
        d.addLine(`富豪金币榜`)
        d.addLine(`探险大师榜`)
        d.addLine(`小队排行榜`)
        d.addLine(`宝可梦大师榜`)
        d.addLine(`宝箱达人榜`)
        d.addLine(`挂机摸鱼榜`)
        d.addLine(`肝帝刷怪榜`)
        d.addLine(`基因锁排行榜`)
        d.addLine(rank_typeName.签到次数)
        d.addLine(rank_typeName.新手任务完成耗时)
        d.addLine(rank_typeName.每周任务完成次数)
        d.addLine(rank_typeName.每日任务完成次数)
        d.addLine(rank_typeName.钓鱼总斤数)
        d.addLine(rank_typeName.砍树次数)
        msg.repeText(d.end())
    }
}
export default new index();